<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <title>游戏注册</title>
  <style>
  body {
  background: url(img/background.jpg);
    display: flex;
    margin-top: 200px;
    margin-left: 1000px;
    background-size:100%;
  }
  a{
    text-decoration:none;
    font-size: 30px;
  }
  </style>
  <script src="/html/Game/js/jquery.min.js"></script>
    <script>
      function goLoginPage(){
       location.href="index.html"}
    function registerAjax(){
      var username=$("#username").val() ;
      var nickname=$("#nickname").val() ;
      var email=$("#email").val() ;
      var password=$("#password").val() ;
      // var confirmPassword=$("#confirmPassword").val() ;
      if (username==null||username.trim()==""){
      alert("账号不能为空");
      return;}
      if (nickname==null||nickname.trim()==""){
        alert("昵称不能为空");
        return;}
      if (email==null||email.trim()==""){
        alert("邮箱不能为空");
        return;}
      if (password==null|| password.trim()==""){
          alert("密码不能为空");
          return;}
      $.ajax({
        type: "post",
        url: "http://localhost:8080/user/register",
        data: {
          username: username,
          nickname: nickname,
          email: email,
          password: password
          // confirmPassword: confirmPassword
        },
        success: function (data) {
          if(data==1){
            alert("恭喜你注册成功")
            location.href="index.html"
          }
          else if(data==-1){
            alert("用户已注册")
          }
          else if(data==-2){
           alert("邮箱重复")
          }
        }
      });
      }
  </script>
</head>
<body>
<div id="login">
  <a>注册账号</a>
  <form name="registerForm" id="registerForm" method="post">
    <p>
      <label for="username">用户名<br/>
        <input type="text" name="username" id="username" class="input"
               size="20" required/></label>
    </p>
    <p>
      <label for="nickname">昵称<br/>
        <input type="text" name="nickname" id="nickname" class="input"
               size="20" required/></label>
    </p>
    <p>
      <label for="email">电子邮箱<br/>
        <input type="text" name="email" class="input" id="email"
               size="20" required/></label>
    </p>
    <p>
      <label for="password">登录密码<br/>
        <input type="password" name="password" id="password" class="input"
               size="20" required/>
      </label>
    </p>
  </form>

  <button onclick="registerAjax()">注册</button>
  <button onclick="goLoginPage()">去登陆</button>
</div>
<div class="clear"></div>
</body>
</html>